<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/8/7
  Time: 15:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.util.List" %>
<%@ page import="com.sun.bean.Books" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    %>
    <!-- 基准路径 -->
    <base href="<%=basePath%>">
    <title>Title</title>

    <script>
        function deleteBoById(id, photo) {
            if (window.confirm("是否要删除？")) {
                location.href = "books?method=deleteBo&id=" + id + "&photo=" + photo;
            }
        }

        //清空数据
        function clearContent() {
            document.getElementById("bname").value = "";
            document.getElementById("op").selected = true;
        }

        //改变条目数
        function changeSize() {
            //1:获取条目数
            var pageSize = document.getElementById("sel").value;
            location.href = "books?method=selectAllBo&bname=${bname}&area=${area}&pageSize="+pageSize;
        }
    </script>
    <style>
        body{
            background: url("/img/23.jpg");
            background-size: 100%;
        }
        h1{
            margin-top: 120px;
        }
        #div {
            margin-left: 350px;
            margin-top: 50px;
        }

        span {
            color: red;
        }
    </style>
</head>

<body>
<h1 align="center">图&nbsp;&nbsp;&nbsp;书&nbsp;&nbsp;&nbsp;信&nbsp;&nbsp;&nbsp;息</h1>
<form style="margin-left:350px;" action="books" >
    <input type="hidden" name="method" value="selectAllBo">
    书名:<input type="text" id="bname" name="bname" value="${bname}">
    状态: <select name="area">
    <option id="op" value="0">请选择状态</option>
    <option ${area eq 1 ? 'selected' : ''} value="1">热销</option>
    <option ${area eq 2 ? 'selected' : ''} value="2">完结</option>
    <option ${area eq 3 ? 'selected' : ''} value="3">下架</option>
    <option ${area eq 4 ? 'selected' : ''} value="4">付费</option>
</select>
    <input type="submit" value="查询">
    <input type="button" onclick="clearContent()" value="清空">
</form>

<table align="center" border="1px" cellspacing="0" width="600px">
    <tr>
        <th>编号</th>
        <th>书贴</th>
        <th>书名</th>
        <th>价格</th>
        <th>作者</th>
        <th>出版社</th>
        <th>日期</th>
        <th>数量</th>
        <th>操作</th>
    </tr>

    <c:forEach items="${list}" var="bk">
        <tr align="center">
            <td>${bk.id}</td>
            <td>
                <img height="40px" width="40px" src="/photo/${bk.photo}">
            </td>
            <td>${bk.bname}</td>
            <td>${bk.price}</td>
            <td>${bk.author}</td>
            <td>${bk.press}</td>
            <td>${bk.pubdate}</td>
            <td>${bk.number}</td>
            <td>
                <a href="books?method=selectOneBo&flag=select&id=${bk.id}">详情</a>
                <a href="javascript:deleteBoById(${bk.id})">删除</a>
                <a href="books?method=selectOneBo&flag=update&id=${bk.id}">修改</a>
            </td>
        </tr>
    </c:forEach>
</table>
<div id="div">
    <a href="books?method=selectAllBo&bname=${bname}&area=${area}&pageSize=${pg.pageSize}">首页</a> &nbsp;&nbsp;
    <a href="books?method=selectAllBo&currentPage=${pg.prePage}&bname=${bname}&area=${area}&pageSize=${pg.pageSize}">上一页</a>&nbsp;&nbsp;
    <a href="books?method=selectAllBo&currentPage=${pg.nextPage}&bname=${bname}&area=${area}&pageSize=${pg.pageSize}">下一页</a>&nbsp;&nbsp;
    <a href="books?method=selectAllBo&currentPage=${pg.totalPages}&bname=${bname}&area=${area}&pageSize=${pg.pageSize}">尾页</a>&nbsp;&nbsp;

    条目数 <select id="sel" onchange="changeSize()">
    <option>3</option>
    <option  ${pg.pageSize == 6 ? 'selected':''}>6</option>
    <option  ${pg.pageSize == 9 ? 'selected':''}>9</option>
</select>
    当前为第 <span>${pg.currentPage}</span>页 / 共<span>${pg.totalPages}</span> 页&nbsp;&nbsp;
    总计为 <span>${pg.totalCount}</span>记录
</div>
</body>
</html>
